package com.hyperfix.washer.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyperfix.common.auth.RequiresRole;
import com.hyperfix.models.common.R;
import com.hyperfix.models.washer.pojos.Station;
import com.hyperfix.models.washer.pojos.Team;
import com.hyperfix.models.washer.vos.TeamVO;
import com.hyperfix.washer.service.TeamService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author JiangChunYu
 * 2024/4/22
 */
@Validated
@RestController
@RequestMapping("/team")
public class TeamController {
    @Resource
    private TeamService teamService;

    /**
     * 查询井队
     *
     * @param pageNum       页码
     * @param size          大小
     * @return {@link R}<{@link IPage}<{@link Team}>> 查询结果
     */
    @PostMapping("/list/{pageNum}/{size}")
    public R<IPage<Team>> list(@PathVariable @Min(value = 1, message = "页号最小不能小于1") Integer pageNum,
                               @PathVariable @Min(value = 1, message = "页大小最小不能小于1") Integer size) {
        return teamService.list(pageNum, size);
    }

    /**
     * 修改井队信息
     *
     * @param teamVO 井队信息 VO
     * @return {@link R}<{@link String}> 是否修改成功
     */
    @RequiresRole("admin")
    @PostMapping("/update")
    public R<String> updateTeam(@RequestBody @Validated TeamVO teamVO) {
        return teamService.updateTeam(teamVO);
    }

    /**
     * 查询指定井队所有站场
     *
     * @param teamId 井队 ID
     * @return {@link R}<{@link List}<{@link Station}>>
     */
    @PostMapping("/listStation/{teamId}")
    public R<List<Station>> listStation(@PathVariable("teamId") @NotNull Integer teamId) {
        return teamService.listStation(teamId);
    }
}
